package com.neuedu.controller;

import com.neuedu.model.*;
import com.neuedu.service.LiveStreamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/live")
public class LiveStreamController {
    @Autowired
    private LiveStreamService liveStreamService;

    // 获取所有直播列表
    @GetMapping("/streams")
    public List<LiveStream> getAllLiveStreams() {
        return liveStreamService.getAllLiveStreams();
    }

    // 根据 ID 获取直播信息
    @GetMapping("/streams/{lsid}")
    public LiveStream getLiveStreamById(@PathVariable Integer lsid) {
        return liveStreamService.getLiveStreamById(lsid);
    }

    // 添加直播
    @PostMapping("/streams")
    public String addLiveStream(@RequestBody LiveStream liveStream) {
        liveStreamService.addLiveStream(liveStream);
        return "直播添加成功";
    }

    // 更新直播信息
    @PutMapping("/streams")
    public String updateLiveStream(@RequestBody LiveStream liveStream) {
        liveStreamService.updateLiveStream(liveStream);
        return "直播信息更新成功";
    }

    // 删除直播
    @DeleteMapping("/streams/{lsid}")
    public String deleteLiveStream(@PathVariable Integer lsid) {
        liveStreamService.deleteLiveStream(lsid);
        return "直播删除成功";
    }

    // 获取直播商品列表
    @GetMapping("/streams/{lsid}/products")
    public List<Product> getLiveProducts(@PathVariable Integer lsid) {
        return liveStreamService.getLiveProducts(lsid);
    }

    // 添加直播商品关联
    @PostMapping("/products")
    public String addLiveProduct(@RequestBody LiveProduct liveProduct) {
        liveStreamService.addLiveProduct(liveProduct);
        return "直播商品关联添加成功";
    }

    // 获取直播互动列表
    @GetMapping("/streams/{lsid}/interactions")
    public List<LiveInteraction> getLiveInteractions(@PathVariable Integer lsid) {
        return liveStreamService.getLiveInteractions(lsid);
    }

    // 添加直播互动
    @PostMapping("/interactions")
    public String addLiveInteraction(@RequestBody LiveInteraction liveInteraction) {
        liveStreamService.addLiveInteraction(liveInteraction);
        return "直播互动添加成功";
    }

    // 获取直播抽奖列表
    @GetMapping("/streams/{lsid}/lotteries")
    public List<LiveLottery> getLiveLotteries(@PathVariable Integer lsid) {
        return liveStreamService.getLiveLotteries(lsid);
    }

    // 添加直播抽奖
    @PostMapping("/lotteries")
    public String addLiveLottery(@RequestBody LiveLottery liveLottery) {
        liveStreamService.addLiveLottery(liveLottery);
        return "直播抽奖添加成功";
    }

    // 参与直播抽奖
    @PostMapping("/lotteries/{llid}/participate")
    public String participateLottery(@PathVariable Integer llid, @RequestParam Integer uid) {
        boolean win = liveStreamService.participateLottery(llid, uid);
        return win ? "恭喜你，中奖了！" : "很遗憾，未中奖。";
    }
}
